<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Comments extends CI_Model {

	public function __construct(){
        parent::__construct();
		$this->load->database('');
       
    }

	public function get_comments($filter=array()){

		$this->db->order_by('create_time','DESC');
		$query=$this->db->get_where('comments',$filter);

		return $query->result();
	}


	public function get_comments_count($result=''){
		
		$query=$this->db->get_where('comments',array('result'=>$result));

		return count($query->result());
	}

	public function get_month_data($result){
		$month_data=array();
		$time=strtotime(date('Y-m',time()));
		for($i=0;$i<6;$i++){

			$filter=array(
				'result'=>$result,
				'create_time <'=> ($time-2592000*$i),
				'create_time >'=>($time-2592000*($i+1)),
			);
			$comments=$this->get_comments($filter);
			$nums=count($comments);
			$month_data[($time-2592000*($i+1))]=$nums;
		}

		return $month_data;
	}

}	